package org.kordakus.shoot.gui.action;

import java.io.File;
import java.util.Arrays;

import javax.swing.JFileChooser;

import org.apache.log4j.Logger;
import org.kordakus.shoot.ShootController;
import org.kordakus.shoot.gui.ShootFrame;
import org.kordakus.shoot.gui.ShootGuiUtils;

public class AddFileAction extends ShootApplicationAsyncAction
{

	private static final long	serialVersionUID	= 8085375862961643101L;

	private static final Logger	_logger				= Logger.getLogger(AddFileAction.class);

	private JFileChooser		_chooser;

	public AddFileAction(ShootFrame frame, ShootController controller)
	{
		super(frame, controller, "Add files", ShootGuiUtils.IMAGE_ADD_FILE);
		initializeObject();
	}

	private void initializeObject()
	{
		_chooser = new JFileChooser();
		_chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		_chooser.setMultiSelectionEnabled(true);
	}

	@Override
	protected void doAction()
	{
		_logger.info("Adding files...");
		if (_chooser.showOpenDialog(getFrame()) == JFileChooser.APPROVE_OPTION)
		{
			getController().importFiles(
					Arrays.asList(_chooser.getSelectedFiles()));
		}
		_chooser.setSelectedFiles(new File[0]);
	}

}
